import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:flutter_local/base/BaseItemPage.dart';

class HttpPage extends BaseItemPage {
  HttpPage({super.key});

  final dio = Dio();

  @override
  List<Widget> getItems() {
    return <Widget>[
      addItemWidget("Get", () {
        easyGet();
      }),
      addItemWidget("POST(表单)", () {}),
      addItemWidget("POST(JSON)", () {})
    ];
  }

  void easyGet() async {
    final rsp = await dio.get("https://api.oick.cn/dutang/api.php");
    print("Get运行结果：$rsp");
  }

  void easyPost() async {
    var rsp = await dio.post("/test", data: {'age': 12, 'name': "user"});
  }

  void easyPostForm() async {
    var formData = FormData.fromMap({"name": "user", "age": 12});
    var rsp = await dio.post('/info', data: formData);}
}
